package java8.test;

public class Learning01 {

    public static void main(String[] args) {

        //无返回值
        Jisuan01 jisuan01 = x -> System.out.println(x);
        jisuan01.op(1);

        //有返回值
        Jisuan02 jisuan02 = x -> {
            System.out.println(x);
            return x * 2;
        };
        int s2 = jisuan02.op(1);
        System.out.println(s2);

        //方法引用
        //1、对象引用
        Jisuan03 jisuan03 = (x, y) -> new Learning01().add1(x, y);
        int s3 = jisuan03.op(1, 2);
        System.out.println(s3);
        //2、静态引用
        Jisuan03 jisuan031 = Learning01::add2;
        int s31 = jisuan031.op(1, 2);
        System.out.println(s31);

    }

    public int add1(int x, int y){
        return x + y;
    }

    private static int add2(int x, int y){
        return x + y;
    }

}

@FunctionalInterface
interface Jisuan01{
    void op(int x);
}

interface Jisuan02{
    int op(int x);
}

interface Jisuan03{
    int op(int x, int y);
}
